package com.yanqu.road.server.cmd.activity.tonbing.cross;

import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.TonBingProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.PreReduceModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = GameProtocol.S_TON_BING_USE_WAR_DRUM_FROM_CROSS, desc = "")
public class TonBingUseWarDrumFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        TonBingProto.CrossTonBingUseWarDrumRespMsg reqMsg = TonBingProto.CrossTonBingUseWarDrumRespMsg.parseFrom(packet.getBytes());
        TonBingProto.TonBingUseWarDrumRespMsg resp = reqMsg.getResp();
        String cost = reqMsg.getCost();

        // 返还预扣除
        player.getModule(PreReduceModule.class).restorePreReduce(cost);

        // 成功了要扣消耗
        if (resp.getRet() == 0) {
            Property property = PropertyHelper.parseStringToProperty(cost);
            player.getModule(CurrencyModule.class).removeCurrency(property, eLogMoneyType.TonBing, eLogMoneyType.TonBingUseWarDrum);
        }

        // 返回
        player.sendPacket(ClientProtocol.U_TON_BING_USE_WAR_DRUM, resp.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
